package models

import (
	"github.com/astaxie/beego/orm"
	"time"
)

type Config struct {
	Id         int `orm:"auto"`
	Describe   string
	Field      string
	Value      string
	Created_at time.Time `orm:"auto_now_add;type(datetime)"`
	updated_at time.Time `orm:"auto_now;type(datetime)"`
	Type       int
}

func ConfigAllList() ([]*Config, error) {
	config := new(Config)
	var list []*Config
	_, err := orm.NewOrm().QueryTable(config).All(&list)
	return list, err
}

func ConfigValueByField(field string, value string) error {
	config := new(Config)
	_, err := orm.NewOrm().QueryTable(config).Filter("field", field).Update(orm.Params{
		"value": value,
	})
	return err
}
